package server;

import java.io.IOException;
import java.net.Socket;

public class AcceptConnectionThread extends Thread{
    TestingServer host;

    public AcceptConnectionThread(TestingServer host){
        this.host = host;
    }

    public void run(){
        host.serverGUI.addLine("Connection thread started.");
        host.serverGUI.addLine("Accepting new connections.");
        while(true){
            try {
                Socket connection = host.serverSocket.accept();
                host.serverGUI.addLine("Connection received from " + connection.getInetAddress().getHostName());
                host.connectionManager.addConnection(new ClientConnection(connection, host));
            } catch (IOException e) {
                e.printStackTrace();
                host.serverGUI.addLine("Retrying connection.");
            }
        }
    }
}
